<?php

namespace App\Models\Applet\Sponsor;

class SlaughterIntegralRecordsModel extends BaseSponsorModel
{
    protected $table = 'slaughter_integral_records';

    /**
     * 根据用户申请宰杀记录id查询数据
     *
     * @param int $userSlaughterRecordsId
     * @param array $fields
     * @return array
     */
    public function getItemByUserSlaughterRecordsId(int $userSlaughterRecordsId, array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        $result = $this->select($fields)
                       ->where('user_slaughter_records_id', $userSlaughterRecordsId)
                       ->where('deleted', self::DELETED_NO)
                       ->first();
        return $result ? $result->toArray() : [];
    }

    public function getItemByUserSlaughterRecordIds(array $userSlaughterRecordsIds, array $fields = self::QUERY_DEFAULT_FIELDS)
    {
        return $this->select($fields)
                    ->join("user_integral_records", 'slaughter_integral_records.user_integral_records_id', '=', 'user_integral_records.id')
                    ->whereIn('user_slaughter_records_id', $userSlaughterRecordsIds)
                    ->where('slaughter_integral_records.deleted', self::DELETED_NO)
                    ->get()
                    ->toArray();
    }
}

